# Makefile.in for kernel module

SHELL = /bin/sh
INSTALL = @INSTALL@
mkdir_p = mkdir -p
VERSION = @PACKAGE_VERSION@
OFED_CFLAGS = @OFED_CFLAGS@
XIO_SYMVERS = @XIO_SYMVERS@
PRIVATE_COMMON = .common

NOSTDINC_FLAGS += @OFED_CFLAGS@

DISTFILES = Makefile.in configure.ac configure ../install-sh \
	xio_log.h  xio_mem.h  xio_os.h xio_mempool.h \
	../../common/common/xio_observer.h \
	xio_context.c xio_ev_loop.c xio_mempool.c \
	xio_init.c xio_mem.c xio_task.c xio_kernel_utils.c \
	xio_workqueue.c	xio_sg_iov.c xio_sg_iovptr.c xio_sg_scatter.c \
	xio_sg_table.c \
	../../../version.c		\
	../../common/xio_objpool.c 	\
	../../common/xio_nexus.c 	\
	../../common/xio_nexus_cache.c	\
	../../common/xio_options.c 	\
	../../common/xio_session.c 	\
	../../common/xio_session_server.c	\
	../../common/xio_session_client.c	\
	../../common/xio_transport.c \
	../../common/xio_connection.c \
	../../common/xio_error.c \
	../../common/xio_server.c \
	../../common/xio_sessions_cache.c \
	../../common/xio_observer.c \
	../../common/xio_idr.c \
	../../common/xio_utils.c \
	../transport/xio_ktransport.c

#TODO: add prefix here to manage directory, where to place headers
includedir = /opt/xio/include
xiomoduledir = @kmoduledir@/extra/net/xio

xiomodule := xio_core.ko

all: all-@ENABLE_XIO_MODULE@
install: install-@ENABLE_XIO_MODULE@
uninstall: uninstall-@ENABLE_XIO_MODULE@

all-n:
install-n:
uninstall-n:

all-y: all-spec

SUBDIRS ?=`pwd`

install-y: all
	$(mkdir_p) $(DESTDIR)$(xiomoduledir)
	$(mkdir_p) $(DESTDIR)$(includedir)
	$(INSTALL) -m 644 $(xiomodule) $(DESTDIR)$(xiomoduledir)/$(xiomodule)
	$(INSTALL) -m 644 $(SUBDIRS)/../../../include/libxio.h $(DESTDIR)$(includedir)
	$(INSTALL) -m 644 $(SUBDIRS)/../../../include/xio_base.h $(DESTDIR)$(includedir)
	$(INSTALL) -m 644 $(SUBDIRS)/../../../include/xio_kernel.h $(DESTDIR)$(includedir)
	$(INSTALL) -m 644 Module.symvers $(DESTDIR)$(includedir)
	-/sbin/depmod -a

uninstall-y:
	rm -f $(DESTDIR)$(xiomoduledir)/$(xiomodule)
	-/sbin/depmod -a

clean:
	-rm -f $(xiomodule) *.o .*.cmd *.mod.c *.ko *.s */*.o *.order *.symvers *.unsigned
	-rm -rf $(PRIVATE_COMMON)

distclean: clean
	rm -f Makefile configure config.status
	rm -f config.h config.log config.status config.cache
	rm -rf .tmp_versions autom4te.cache

maintainer-clean: distclean

distdir: $(DISTFILES)
	cp -p $(DISTFILES) $(distdir)


ccflags-y += $(OFED_CFLAGS) -I$(SUBDIRS) -I$(SUBDIRS)/.. -I$(SUBDIRS)/../../common -I$(SUBDIRS)/../../common -I$(SUBDIRS)/../../../include -I$(SUBDIRS)/../../libxio_os/linuxkernel

obj-m := xio_core.o
xio_core-objs := \
	xio_init.o \
	xio_context.o \
	xio_ev_loop.o \
	xio_mempool.o \
	xio_init.o \
	xio_mem.o \
	xio_task.o \
	xio_kernel_utils.o \
	xio_workqueue.o \
	xio_sg_iov.o	\
	xio_sg_iovptr.o	\
	xio_sg_scatter.o \
	xio_sg_table.o	\
	../transport/xio_ktransport.o	\
	$(PRIVATE_COMMON)/version.o \
	$(PRIVATE_COMMON)/xio_objpool.o \
	$(PRIVATE_COMMON)/xio_nexus.o \
	$(PRIVATE_COMMON)/xio_nexus_cache.o \
	$(PRIVATE_COMMON)/xio_options.o \
	$(PRIVATE_COMMON)/xio_session.o \
	$(PRIVATE_COMMON)/xio_session_server.o	\
	$(PRIVATE_COMMON)/xio_session_client.o	\
	$(PRIVATE_COMMON)/xio_transport.o \
	$(PRIVATE_COMMON)/xio_connection.o \
	$(PRIVATE_COMMON)/xio_error.o \
	$(PRIVATE_COMMON)/xio_server.o \
	$(PRIVATE_COMMON)/xio_sessions_cache.o \
	$(PRIVATE_COMMON)/xio_observer.o \
	$(PRIVATE_COMMON)/xio_idr.o \
	$(PRIVATE_COMMON)/xio_utils.o

$(PRIVATE_COMMON):
	$(mkdir_p) $@
	cp -ps `pwd`/../../../version.c $@/
	cp -ps `pwd`/../../common/*.c $@/
	cp -ps `pwd`/../../common/*.h $@/

all-spec: $(PRIVATE_COMMON)
	export NOSTDINC_FLAGS
	$(MAKE) -C @kernelsrc@ SUBDIRS=`pwd` @KERNELMAKE_PARAMS@ KBUILD_EXTRA_SYMBOLS=$(XIO_SYMVERS) modules
